// geometric_main.cpp
// 04/15/2011 : created

#include <iostream>
#include <fstream>
#include <QtGui/QApplication>

#include "geometric_main_window.h"
#include "Log.h"
#include "arma_vector.h"

void createToyExample() 
{
  std::ofstream os("toy.dat");
  int n = 5, d = 2;
  os << n << " " << d << std::endl;
  std::vector<vec> v(n, vec(2));
  v[0][0] = -5;   v[0][1] = -5;
  v[1][0] = 5; v[1][1] = -5;
  v[2][0] = 5; v[2][1] = 5;
  v[3][0] = 0;   v[3][1] = 0;
  v[4][0] = -5;   v[4][1] = 5;
  for (int i = 0; i < n; i++) {
    v[i].save(os, arma::arma_ascii);
  }
  os.close();
}

void createToyExample1() 
{
  std::ofstream os("toy1.dat");
  int n = 6, d = 2;
  os << n << " " << d << std::endl;
  std::vector<vec> v(n, vec(2));
  v[0][0] = -5;   v[0][1] = -5;
  v[1][0] = 5; v[1][1] = -5;
  v[2][0] = 5; v[2][1] = 5;
  v[3][0] = 0;   v[3][1] = 0;
  v[4][0] = -4;   v[4][1] = -4;
  v[5][0] = 0;   v[5][1] = -5;
  for (int i = 0; i < n; i++) {
    v[i].save(os, arma::arma_ascii);
  }
  os.close();
}

void createToyExample2() 
{
  int n = 2, d = 2;
  std::vector<vec> v(n, vec(2));

  std::ofstream os("toy1.dat");
  os << n << " " << d << std::endl;
  v[0][0] = 0;   v[0][1] = 0;
  v[1][0] = 2; v[1][1] = 0;
  for (int i = 0; i < n; i++) {
    v[i].save(os, arma::arma_ascii);
  }
  os.close();

  std::ofstream os1("toy2.dat");
  os1 << n << " " << d << std::endl;
  v[0][0] = 1;   v[0][1] = 0;
  v[1][0] = 0; v[1][1] = 10;
  for (int i = 0; i < n; i++) {
    v[i].save(os1, arma::arma_ascii);
  }
  os1.close();
}

void createRandomExample(const char* fname) 
{
  std::ofstream os(fname);
  int n = 200, d = 2;
  os << n << " " << d << std::endl;
  std::vector<vec> v(n, vec(2));
  vec v5(2); v5.randn(); v5 *= 2;
  std::cout << "v5=\n" << v5 << std::endl;
  for (int i = 0; i < n; i++) {
    v[i].randn();
    v[i] *= 4;
    v[i] -= v5;
    v[i].save(os, arma::arma_ascii);
  }
  os.close();
}

int main(int argc, char** argv) 
{
  Log::m_log.setCodec("UTF-8"); 
  Log::m_log << "Geometric v1.0... " << endl;
  createToyExample2();
	QApplication a(argc, argv);
	MainWindow w("Geometric");
  w.resize(500, 500);
	w.show();
	return a.exec();
}
